package com.xsprite.managesys.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xsprite.managesys.bean.QueryRoleInfo;
import com.xsprite.managesys.bean.QueryServer;
import com.xsprite.managesys.service.ServersDatabaseManager;

/**
 * Servlet implementation class QueryUserInfo
 */
public class QueryUserInfo extends BaseServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.service(req, resp);
		if(isParameterNull("playerName") || isParameterNull("serverId")){
			return;
		}
		String playerName = queryParam("playerName");
		String serverId = queryParam("playerName");
		
		QueryServer server = ServersDatabaseManager.getInstance().getServerById(Integer.parseInt(serverId));
		try{
			QueryRoleInfo queryRoleInfo = ServersDatabaseManager.getInstance().queryRoleInfo(server.getGameDBId(), playerName);
			queryRoleInfo.setServerId(Integer.parseInt(serverId));
			req.setAttribute("queryRoleInfo", queryRoleInfo);
		} catch (Exception ex){
			QueryRoleInfo queryRoleInfo = new QueryRoleInfo();
			queryRoleInfo.setServerId(Integer.parseInt(serverId));
			queryRoleInfo.setRolename(playerName);
		}
		
		ServersDatabaseManager manager = ServersDatabaseManager.getInstance();
		List<QueryServer> servers = manager.getServersLsit();
		req.setAttribute("queryServers", servers);
		forwardTo("/view/queryUserInfo.jsp");
	}
}
